package com.example.homework2;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;

import com.example.homework2.Interface.UC1;
import com.example.homework2.Interface.UC2;
import com.example.homework2.Interface.UC3;
import com.example.homework2.Interface.UC4;
import com.example.homework2.Interface.UC5;

public class MainActivity extends AppCompatActivity {

    LinearLayout button_linearlayout;

    String[] layout_name = {"线性布局", "相对布局", "帧布局", "表格布局", "网格布局", "RecyclerView", "垂直ViewPage", "水平ViewPage"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button_linearlayout = findViewById(R.id.button_linearlayout);

        for (int i = 0; i < layout_name.length; i++) {
            View view = LayoutInflater.from(this).inflate(R.layout.button_layout, null);
            Button which_layout = view.findViewById(R.id.which_layout);
            which_layout.setText(layout_name[i]);
            int finalI = i;
            which_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (finalI == 0) {
                        Intent intent = new Intent(MainActivity.this, UC1.class);
                        startActivity(intent);
                    }
                    else if (finalI == 1) {
                        Intent intent = new Intent(MainActivity.this, UC2.class);
                        startActivity(intent);
                    }
                    else if (finalI == 2) {
                        Intent intent = new Intent(MainActivity.this, UC3.class);
                        startActivity(intent);
                    }
                    else if (finalI == 3) {
                        Intent intent = new Intent(MainActivity.this, UC4.class);
                        startActivity(intent);
                    }
                    else if (finalI == 4) {
                        Intent intent = new Intent(MainActivity.this, UC5.class);
                        startActivity(intent);
                    }
                    else if (finalI == 5) {
                        Intent intent = new Intent(MainActivity.this, Recyclerview.class);
                        startActivity(intent);
                    }
                    else if (finalI == 6) {
                        Intent intent = new Intent(MainActivity.this, ViewPage_2.class);
                        startActivity(intent);
                    }
                    else if (finalI == 7) {
                        Intent intent = new Intent(MainActivity.this, H_ViewPage_2.class);
                        startActivity(intent);
                    }
                }
            });
            button_linearlayout.addView(view);
        }
    }
}